package cn.com.ourclass.webviewnew.web.tools;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.support.v4.app.ActivityCompat;

/**
 * Created by Administrator on 2017/4/20.
 */

public class GetPermissionUtils {
    protected static final int TAKE_PICTURE = 1;
    protected static final int REQUEST_EXTERNAL_STRONGE = 1;
    /**
     * 申请相机权限
     */
    public static String requestCameraPermission(Context context) {
        // 相机权限未被授予，需要申请！
        if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context,
                Manifest.permission.CAMERA)) {
            // 如果访问了，但是没有被授予权限，则需要告诉用户，使用此权限的好处
            // 这里重新申请权限
            ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.CAMERA}, TAKE_PICTURE);
        } else {
            ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.CAMERA}, TAKE_PICTURE);
        }
        return "1";
    }

    /**
     * 申请读写权限
     */
    public static String requestSavePermission(Context context) {
        // 存储权限未被授予，需要申请！
        if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_STRONGE);
        }else {
            ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_STRONGE);
        }
        return "1";
    }


    /**
     * 申请麦克风权限
     */
    public static String requestMarkPermission(Context context) {
        // 麦克权限未被授予，需要申请！
        if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context,
                Manifest.permission.RECORD_AUDIO)) {
            ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.MODIFY_AUDIO_SETTINGS, Manifest.permission.RECORD_AUDIO}, REQUEST_EXTERNAL_STRONGE);
        }else {
            ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.MODIFY_AUDIO_SETTINGS, Manifest.permission.RECORD_AUDIO}, REQUEST_EXTERNAL_STRONGE);
        }
        return "1";
    }

}
